
package com.insigma.business.qrcode.soldier.service.impl;


import com.insigma.business.qrcode.common.service.SequenceGenerator;
import com.insigma.business.qrcode.common.util.AdminAreaCodeUtils;
import com.insigma.business.qrcode.soldier.dao.JobRecruitPositionDao;
import com.insigma.business.qrcode.job.dto.search.JobRecruitPositionBSearcher;
import com.insigma.business.qrcode.soldier.entity.DataStatsCDO;
import com.insigma.business.qrcode.soldier.entity.JobRecruitPositionDO;
import com.insigma.business.qrcode.soldier.service.JobRecruitPositionService;
import org.apache.logging.log4j.util.Strings;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;


@Service("jobRecruitPositionService")
public class JobRecruitPositionServiceImpl implements JobRecruitPositionService {

    @Autowired(required = false)
    private JobRecruitPositionDao jobRecruitPositionDao;
    @Autowired(required = false)
    private SequenceGenerator sequenceGenerator;

    
    @Override
    public List<JobRecruitPositionDO> search(final JobRecruitPositionBSearcher jobRecruitPositionBSearcher) {
        return jobRecruitPositionDao.search(jobRecruitPositionBSearcher);
    }
   
    @Override
    public JobRecruitPositionDO get(final String id){
        return jobRecruitPositionDao.get(id);
    }

    
    @Override
    public Integer insert(final JobRecruitPositionDO jobRecruitPositionDO){
        jobRecruitPositionDO.setId(sequenceGenerator.genKey("JOB_RECRUIT_POSITION_ID"));
        return jobRecruitPositionDao.insert(jobRecruitPositionDO);
    }

    
    @Override
    public Integer update(final JobRecruitPositionDO jobRecruitPositionDO){
        return jobRecruitPositionDao.update(jobRecruitPositionDO);
    }

    
    @Override
    public Integer delete(final String id, final String modifierType, final String modifierId){
        return jobRecruitPositionDao.delete(id,modifierType,modifierId);
    }

    @Override
    public List<JobRecruitPositionDO> searchFavoritePosition(JobRecruitPositionBSearcher jobRecruitPositionBSearcher) {
        return jobRecruitPositionDao.searchFavoritePosition(jobRecruitPositionBSearcher);
    }

    @Override
    public List<JobRecruitPositionDO> listPositionsOfCompany(String companyId) {
        return jobRecruitPositionDao.listPositionsOfCompany(companyId);
    }

    @Override
    public Integer count(String companyId) {
        return jobRecruitPositionDao.count(companyId);
    }

    @Override
    public List<String> selectAllTypeName(String companyId) {
        return jobRecruitPositionDao.selectAllTypeName(companyId);
    }

    @Override
    public List<DataStatsCDO> selectTop10Delivery(String companyId) {
        return jobRecruitPositionDao.selectTop10Delivery(companyId);
    }

    @Override
    public int countByBetweenTime(Date startTime, Date endTime, String companyId) {
        return jobRecruitPositionDao.countByBetweenTime(startTime, endTime, companyId);
    }

    @Override
    public int countNeedPosNumByBetweenTime(Date startTime, Date endTime, String companyId) {
        return jobRecruitPositionDao.countNeedPosNumByBetweenTime(startTime, endTime, companyId);
    }

    @Override
    public int unpublishJobFair(String fairId) {
        return jobRecruitPositionDao.unpublishJobFair(fairId);
    }

    @Override
    public int countByFair(String id) {
        return jobRecruitPositionDao.countByFair(id);
    }

    @Override
    public void unpublishByDate(Date date) {
        jobRecruitPositionDao.unpublishByDate(date);
    }

    @Override
    public Integer countRecruitNum(JobRecruitPositionBSearcher jobRecruitPositionBSearcher) {
        if (Strings.isNotBlank(jobRecruitPositionBSearcher.getLegalAreaCode())) {
            jobRecruitPositionBSearcher.setLegalAreaCode(AdminAreaCodeUtils.getCutdAreaCode(jobRecruitPositionBSearcher.getLegalAreaCode()));
        }
        return jobRecruitPositionDao.countRecruitNum(jobRecruitPositionBSearcher);
    }

    @Override
    public Integer countRecruitNeedNum(JobRecruitPositionBSearcher jobRecruitPositionBSearcher) {
        if (Strings.isNotBlank(jobRecruitPositionBSearcher.getLegalAreaCode())) {
            jobRecruitPositionBSearcher.setLegalAreaCode(AdminAreaCodeUtils.getCutdAreaCode(jobRecruitPositionBSearcher.getLegalAreaCode()));
        }
        return jobRecruitPositionDao.countRecruitNeedNum(jobRecruitPositionBSearcher);
    }

    @Override
    public List<String> selectAllTypeNameByArea(String adminAreaCode) {
        return jobRecruitPositionDao.selectAllTypeNameByArea(AdminAreaCodeUtils.getCutdAreaCode(adminAreaCode));
    }

    @Override
    public Integer sumRecruitNum(JobRecruitPositionBSearcher jobRecruitPositionBSearcher) {
        if (Strings.isNotBlank(jobRecruitPositionBSearcher.getLegalAreaCode())) {
            jobRecruitPositionBSearcher.setLegalAreaCode(AdminAreaCodeUtils.getCutdAreaCode(jobRecruitPositionBSearcher.getLegalAreaCode()));
        }
        return jobRecruitPositionDao.sumRecruitNum(jobRecruitPositionBSearcher);
    }

    @Override
    public List<DataStatsCDO> groupJobCountByArea(String adminAreaCode) {
        int level = AdminAreaCodeUtils.getLevel(adminAreaCode);
        adminAreaCode = AdminAreaCodeUtils.getCutdAreaCode(adminAreaCode) ;
        int nextLevel = level + 1;
        int levelLength = AdminAreaCodeUtils.getLevelLength(nextLevel);
        return jobRecruitPositionDao.groupJobCountByArea(adminAreaCode, nextLevel, levelLength);
    }

    @Override
    public List<JobRecruitPositionDO> searchByOrgId(String orgId) {
        return jobRecruitPositionDao.searchByOrgId(orgId);
    }

    @Override
    public void deleteByOnlineFairOrg(String orgId) {
        jobRecruitPositionDao.deleteByOnlineFairOrg(orgId);
    }
}
